import { ApiProperty } from '@nestjs/swagger';
import {
  BeforeInsert,
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserClient } from '../../userClient/assets/userClient.entity';

@Entity('inviterelation')
export class InviteRelation {
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '邀请者用户Id', type: () => UserClient })
  @ManyToOne(() => UserClient, { cascade: ['remove'], onDelete: 'CASCADE' })
  inviter: UserClient;

  @ApiProperty({ description: '被邀请者用户Id', type: () => UserClient })
  @OneToOne(() => UserClient, { cascade: ['remove'], onDelete: 'CASCADE' })
  @JoinColumn()
  invitee: UserClient;

  @Column({
    type: 'bigint',
    nullable: true,
  })
  @ApiProperty({ description: '创建时间' })
  createTime: number;

  @BeforeInsert()
  setCreateTime() {
    this.createTime = Math.floor(Date.now() / 1000); // 使用秒级时间戳
  }
}
